<?php 
$watermarkConfig = array('options' => array());
$postConfig = (array) system_controller_front::getInstance()->getRequest()->getPost('watermark');
if(empty($postConfig)) {
	$systemConfig = (array) resource_config_image::getWatermark();
	$watermarkConfig['enable'] = isset($systemConfig['enable']) && $systemConfig['enable'];
	if(isset($systemConfig['filename'])) $watermarkConfig['filename'] = $systemConfig['filename'];
	if(isset($systemConfig['options'])) $watermarkConfig['options'] = array_merge($watermarkConfig['options'], $systemConfig['options']);
} else {
	$watermarkConfig['enable'] = isset($postConfig['enable']) && $postConfig['enable'];
	if(isset($postConfig['filename'])) $watermarkConfig['filename'] = $postConfig['filename'];
	if(isset($postConfig['options'])) $watermarkConfig['options'] = array_merge($watermarkConfig['options'], $postConfig['options']);
}
$values = array();
$values['enable'] = isset($watermarkConfig['enable']) && $watermarkConfig['enable'] ? 1 : 0;
$values['filename'] = isset($watermarkConfig['filename']) ? trim($watermarkConfig['filename']) : 'watermark.png';
$values['options']['position'] = isset($watermarkConfig['options']['position']) ? intval($watermarkConfig['options']['position']) : 9;
$values['options']['margin'] = isset($watermarkConfig['options']['margin']) ? intval($watermarkConfig['options']['margin']) : 1;
$values['options']['minWidth'] = isset($watermarkConfig['options']['minWidth']) ? intval($watermarkConfig['options']['minWidth']) : 500;
$values['options']['minHeight'] = isset($watermarkConfig['options']['minHeight']) ? intval($watermarkConfig['options']['minHeight']) : 500;
?><fieldset class="opt">
<legend>
	<input type="checkbox" name="watermark[enable]" id="watermark" value="1"<?php if($watermarkConfig['enable']) echo ' checked="checked';?> />
	<label for="watermark" class="for-checkbox"><?php echo $this->language('Enable Watermark');?></label>
</legend>
<ul>
	<li>
		<span style="display:block;"><?php echo $this->language('Mark File');?>:</span>
		<?php echo $this->form()->text('watermark[filename]', $values['filename'], array('size' => '30'));?>
		<code><?php echo $this->language('Base Dir') . ':' . _DIRECTORY_SETTING . DIRECTORY_SEPARATOR . $this->language()->getHtmlLanguageName();?></code>
		<code><?php echo $this->language('Default') . ': watermark.png';?></code>
	</li>
	<li>
		<span style="display:block;"><?php echo $this->language('Mark Position');?>:</span>
		<div><?php 
		echo '<div style="float:left;width:100px;">';
		for($i = 1; $i <= 9; $i++) {
			echo '<input type="radio" name="watermark[options][position]" id="watermark-option-position-' . $i . '" value="' . $i . '"';
			if($values['options']['position'] == $i) echo ' checked="checked"';
			echo ' />';
			echo '<label for="watermark-option-position-' . $i . '" class="for-checkbox">' . $i . '</label>';
			if($i % 3 == 0) {
				echo '<br/>';
			}
		}
		echo '</div>';
		echo '<div style="float:left;">';
		echo '<input type="radio" name="watermark[options][position]" id="watermark-option-position-0" value="0"';
		if($values['options']['position'] == 0) echo ' checked="checked';
		echo ' />';
		echo '<label for="watermark-option-position-0" class="for-checkbox">' . $this->language('Random') . '</label>';
		echo '</div>';
		?></div>
		<div class="clear"></div>
	</li>
	<li>
		<span style="display:block;"><?php echo $this->language('Margin Width');?>:</span>
		<?php echo $this->form()->text('watermark[options][margin]', $values['options']['margin'], array('size' => '10', 'maxlength' => '3'));?>(px)
		<code><?php echo $this->language('The width between the Watermark and the Original image.Must be an integer');?>.</code>
	</li>
	<li>
		<span><?php echo $this->language('Minimum Dimension');?>:</span>
		<code><?php echo $this->language('Width');?>(px)</code>
		<?php echo $this->form()->text('watermark[options][minWidth]', $values['options']['minWidth'], array('size' => '10', 'maxlength' => '5'));?>(px)
		<code><?php echo $this->language('Height');?>(px)</code>
		<?php echo $this->form()->text('watermark[options][minHeight]', $values['options']['minHeight'], array('size' => '10', 'maxlength' => '5'));?>(px)
		<code><?php echo $this->language('The original image will not watermarked when it\'s dimension less than the values you set');?>.</code>
	</li>
</ul>
</fieldset>